#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
# File Name: built_in_install.sh
# Author: GID5564
# Description:  安装常用的命令
# Created Time: 28/08/25-10:04:39
#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
#! /bin/bash

function base_install(){
    #更新
    sudo apt update && sudo apt upgrade
    #基础软件包
    build_in_apt 'others'
    build_in_apt 'base'
    build_in_apt 'compi'
    build_in_apt 'tool'
    #安装vim
    install_vim
    #中文支持
    set_locales
    #时区
    set_tzdata
}




function built_in_install(){
    local section=${1}  
    local key=${2}          
    local BUILT_IN_COMMAND=""
    [[ -z "${section}" || -z "${key}" ]] && {
        error "Usage: built_in_install <section name[apt|pip]> <key name>"
        return $INVALID_ARGUMENTS
    }

    case ${section} in
        "apt")
            BUILT_IN_COMMAND="install_dpkg_package"
            ;;
        "pip")
            BUILT_IN_COMMAND="install_python_package"
            ;;
        *)
            return $INVALID_ARGUMENTS
            #可以在此增加
            ;;
    esac
    # 检查所选的安装命令是否存在于PATH中  
    command -v "$BUILT_IN_COMMAND" >/dev/null 2>&1 || {        
        error "Command '$BUILT_IN_COMMAND' not found in PATH."  
        return 1    
    }

    # 读取配置文件中的section和key对应的值
    local values=$(read_ini "$FILE_CONFIG" "$section" "$key")

    # 如果值为空，则无需继续    
    if [[ -z "$values" ]]; then        warn "No values found for section '$section', key '$key'."
        return 1 
    fi
    
    IFS=',' read -ra items <<< "$values"
    
    for i in "${!items[@]}"; do
        # 根据内置命令执行相应的安装操作
        "$BUILT_IN_COMMAND" "${items[$i]}"
    done

    # 清理临时变量
    unset BUILT_IN_COMMAND items values key section
}

function build_in_apt(){
    local section=${1}
    built_in_install "apt" ${section}
}
function build_in_pip(){
    local section=${1}
    built_in_install "pip" ${section}
}

function split_csv_to_array() {
    local input_str="$1"
    IFS=',' read -ra items <<< "$input_str"
}
































